#version 460
#extension GL_GOOGLE_include_directive : enable

#include "../../../core/shader_tranform.h"
#include "../../../core/shader_widget_panel.h"
//#include "lib/project_matrix.glsl"

layout(location = 0) in vec2 inPos;
layout(location = 1) in vec2 inWeights;
layout(location = 2) in vec2 inNormal;

layout(location = 0) out vec2 gCoords;
layout(location = 1) out flat uint gInstanceIndex;


 
void main(void) {
	//gl_Position = mat_ProjecView * mat_view * mat_Model[gl_InstanceIndex] * vec4(inPos, 0.0, 1.0);
	gInstanceIndex = gl_InstanceIndex;

	mat3x2 mat = m_LP_SD[gl_InstanceIndex];
	//gl_Position = vec4(inPos + mat.xy, 0.0, 1.0);
	vec4 v = vec4(0.0, 0.0, 0.0, 1.0);

	mat2 rot;
	rot[0] = vec2(cos(mat[2].y), -sin(mat[2].y));
	rot[1] = vec2(sin(mat[2].y), cos(mat[2].y));

	//vec2 vert = rot * inPos;
	vec2 Invert = sign(mat[1]);
	float radius = min(min(abs(mat[1].x), abs(mat[1].y)),  mat[2].x);
	//缩放部分大小
	vec2 scale_size = max(abs(mat[1]) - radius, 0);
	v.xy = (inPos * radius * Invert) + ((scale_size * Invert) * inWeights.xy * rot);
	
	gCoords = v.xy / (mat[1]+1);

	v.xy += mat[0];
	v.xy *= m_Scale;
	v.xy += m_Loc;

	v.xy = round(v.xy) + 0.5;
	gl_Position = mat_ProjecView * v;
	
	gl_PointSize = 4.0;
	
}



